//
// Created by Win on 2016/7/16.
//

#ifndef APM_R3_HTTP_RMI_BASETYPE_H
#define APM_R3_HTTP_RMI_BASETYPE_H

#include "frbyte_buffer.h"
#include "frreport_comm.h"

/**
  * Magic number that is written to the stream header.
  */
#define STREAM_MAGIC            0xaced

/**
 * Version number that is written to the stream header.
 */
#define STREAM_VERSION          5

/* Each item in the stream is preceded by a tag
 */

/**
 * First tag value.
 */
#define TC_BASE                 0x70

/**
 * Null object reference.
 */
#define TC_NULL                 0x70

/**
 * Reference to an object already written into the stream.
 */
#define TC_REFERENCE            0x71

/**
 * new Class Descriptor.
 */
#define TC_CLASSDESC            0x72

/**
 * new Object.
 */
#define TC_OBJECT              0x73

/**
 * new String.
 */
#define TC_STRING              0x74

/**
 * new Array.
 */
#define TC_ARRAY                  0x75

/**
 * Reference to Class.
 */
#define TC_CLASS                  0x76

/**
 * Block of optional data. Byte following tag indicates number
 * of bytes in this block data.
 */
#define TC_BLOCKDATA           0x77

/**
 * End of optional block data blocks for an object.
 */
#define TC_ENDBLOCKDATA           0x78

/**
 * Reset stream context. All handles written into stream are reset.
 */
#define TC_RESET                  0x79

/**
 * long Block data. The long following the tag indicates the
 * number of bytes in this block data.
 */
#define TC_BLOCKDATALONG           0x7A

/**
 * Exception during write.
 */
#define TC_EXCEPTION           0x7B

/**
 * Long string.
 */
#define TC_LONGSTRING             0x7C

/**
 * new Proxy Class Descriptor.
 */
#define TC_PROXYCLASSDESC              0x7D

/**
 * new Enum constant.
 * @since 1.5
 */
#define TC_ENUM                   0x7E

/**
 * Last tag value.
 */
#define TC_MAX                    0x7E

/**
 * First wire handle to be assigned.
 */
#define baseWireHandle              0x7e0000

/******************************************************/
/* Bit masks for ObjectStreamClass flag.*/

/**
 * Bit mask for ObjectStreamClass flag. Indicates a Serializable class
 * defines its own writeObject method.
 */
#define SC_WRITE_METHOD   0x01

/**
 * Bit mask for ObjectStreamClass flag. Indicates Externalizable data
 * written in Block Data mode.
 * Added for PROTOCOL_VERSION_2.
 *
 * @see #PROTOCOL_VERSION_2
 * @since 1.2
 */
#define SC_BLOCK_DATA   0x08

/**
 * Bit mask for ObjectStreamClass flag. Indicates class is Serializable.
 */
#define SC_SERIALIZABLE   0x02

/**
 * Bit mask for ObjectStreamClass flag. Indicates class is Externalizable.
 */
#define SC_EXTERNALIZABLE   0x04

/**
 * Bit mask for ObjectStreamClass flag. Indicates class is an enum type.
 * @since 1.5
 */
#define SC_ENUM   0x10

//变量
typedef struct __rmi_privite_data
{
    struct __rmi_privite_data *head_node;
    struct __rmi_privite_data *next_node;
    struct __rmi_privite_data *tail_node;
    struct __rmi_privite_data_head *child;
} rmiDataChild;

typedef struct __rmi_privite_data_head
{
    int i_size;
    char *p_name;
    uint8_t u8_tcode;
    char *p_object_type;        //class
    int i_type_handle;          //句柄
    int hasData;
    int hasBlockExternalData;
    int externalizable;
    int passhandle;

    struct __rmi_privite_data *child;
    struct __rmi_privite_data_head *super;
    struct __rmi_privite_data_head *next;
    struct __rmi_privite_data_head *tail;

} rmiDataParent;



int object_writeNonProxy(Frbyte_Packet *p_st_data, Frreport_body_data *p_st_body_data, int i_use_request
                         , int *p_i_deep, rmiDataParent **pp_rmi_head, rmiDataParent **pp_rmi_root, uint32_t *p_u32_passHandle, char *p_parent, char *p_prefix);

rmiDataChild* rmiNodeNew(void);

void rmiNodeFree(rmiDataChild *p_data);

rmiDataParent* rmiHeadNew(void);

void rmiHeadFree(rmiDataParent *p_head);

int rmiDataAddChild(rmiDataParent **pp_rmi_head, rmiDataParent **pp_rmi_add);

int rmiDataAddBrother(rmiDataParent **pp_rmi_head, rmiDataParent **pp_rmi_add);

#endif //APM_R3_HTTP_RMI_BASETYPE_H_H
